﻿using System.Windows;
using System.Text.RegularExpressions;

namespace Net.Chirash.Twitter.TweetZone
{
    /// <summary>
    /// OAuthBrowser.xaml の相互作用ロジック
    /// </summary>
    public partial class OAuthBrowser : Window
    {
        public string PIN { get; set; }

        #region Constructors

        public OAuthBrowser()
        {
            InitializeComponent();
        }

        public OAuthBrowser(string url)
        {
            InitializeComponent();
            mainWebBrowser.Navigate(url);
        }

        #endregion

        #region Events

        private void SaveButton_Click(object sender, RoutedEventArgs e)
        {
            Regex reg = new Regex(".*(?<pin>[0-9]{7}).*");
            if (reg.IsMatch(PINTextBox.Text))
            {
                PIN = reg.Match(PINTextBox.Text).Result("${pin}");
                PINTextBox.Text = "";
                DialogResult = true;
                //Close();
            }
            else
            {
                DialogResult = false;
                //Close();
            }
        }

        private void mainWebBrowser_Navigated(object sender, System.Windows.Navigation.NavigationEventArgs e)
        {
            //スクレイピング
        }

        private void CancelButton_Click(object sender, System.Windows.RoutedEventArgs e)
        {
            DialogResult = false;
            //Close();
        }

        #endregion
    }
}